package cn.shiwei.quartz.job;

import cn.shiwei.order.domain.OrderPet;
import cn.shiwei.order.mapper.OrderPetMapper;
import cn.shiwei.pay.domain.PayBill;
import cn.shiwei.pay.mapper.PayBillMapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
@Component
public class OrderExpireJob implements Job {

    @Autowired
    private PayBillMapper payBillMapper;

    @Autowired
    private OrderPetMapper orderPetMapper;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("定时测试");
        Map params = (Map)jobExecutionContext.getJobDetail().getJobDataMap().get("params");
        String sn = (String)params.get("sn");
        // 判断支付单状态是否为未支付, 待支付
        PayBill payBill = payBillMapper.loadBySn(sn);
        if (payBill.getState().intValue() != PayBill.STATUS_PENDING_PAYMENT){
            return;
        }
        // 判断业务单状态是否为未支付, 待支付
        OrderPet order = orderPetMapper.loadBySn(sn);
        if (order.getState().intValue() != OrderPet.STATUS_PENDING_PAYMENT){
            return;
        }

        payBill.setState(PayBill.STATUS_CANCELED);
        Date date = new Date();
        payBill.setUpdateTime(date);

    }
}
